import random
import re
import sys
import time
import logging
import os

import traceback

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from YeMao import setting

logger = logging.getLogger()
logger.setLevel(logging.INFO)
rq = time.strftime('%Y-%m-%d', time.localtime(time.time()))
log_path = os.path.dirname(os.getcwd()) + '/SeleniumAutoTest/'
log_name = log_path + rq + '.txt'  # 文件名字决定文件数量
logfile = log_name
fh = logging.FileHandler(logfile, mode='a+', encoding='utf-8')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)

# dr = webdriver.Chrome(setting.WEBDRIVERURI)
# dr.implicitly_wait(10)
# dr.maximize_window()


def logtofile(message,fun):
    """
    写入日志
    :param message: 消息
    :return:
    """
    print('sss')
    lt = time.strftime('%Y-%m-%d:%H-%M-%S', time.localtime(time.time()))
    # logger.info("{lt}-{msg}".format(lt=lt, msg=message))
    fun("{lt}-{msg}".format(lt=lt, msg=message))
    print('sss')

logtofile('hahaha',logger.info)
